Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve TruncateTime canonical function performance #948

Merged
merged 4 commits into from
Jul 1, 2019

Conversation

brandondahler
Copy link
Contributor

Ported from CodePlex, taking back over from #467 .

Updates TruncateTime function from

TruncateTime(DateTime X)	        
    PreKatmai:    TRUNCATETIME(X) => CONVERT(DATETIME, CONVERT(VARCHAR(255), expression, 102),  102)
    Katmai:    TRUNCATETIME(X) => CONVERT(DATETIME2, CONVERT(VARCHAR(255), expression, 102),  102)
TruncateTime(DateTimeOffset X)
    TRUNCATETIME(X) => CONVERT(datetimeoffset, CONVERT(VARCHAR(255), expression,  102) + ' 00:00:00 ' +  Right(convert(varchar(255), @arg, 121), 6),  102)

to

TruncateTime(DateTime X)
PreKatmai:    TRUNCATETIME(X) => DATEADD(d, DATEDIFF(d, 0, expression), 0)
Katmai:       TRUNCATETIME(X) => CAST(CAST(expression AS DATE) as DATETIME2)

TruncateTime(DateTimeOffset X)
Katmai only: TRUNCATETIME(X) => TODATETIMEOFFSET(CAST(expression AS DATE), DATEPART(tz, expression))

@brandondahler
Copy link
Contributor Author

Addressed latest nits, fixed broken tests, and rebased upon current master. Recommend closing #467 in favor of this PR.

@brandondahler
Copy link
Contributor Author

Honestly not sure why the test returns one way on my machine and another on the CI machine. Reverting the test change. I don't believe that SqlServer CE has CAST(... as Date)

@ajcvickers ajcvickers merged commit 7ec4dde into dotnet:master Jul 1, 2019
@ajcvickers
Copy link
Contributor

Thanks @brandondahler for the contribution!

@vslee
Copy link

vslee commented Nov 27, 2019

resolves #824

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants